﻿using System.Collections.Generic;
using System.Data.Linq;
using mal.balades.Business.DataModel;

namespace mal.balades.Business.DataAccess
{
    /// <summary>
    /// Deprecated
    /// </summary>
    public class VisitQualityDataAccess : BaseDataAccess
    {
        public VisitQualityDataAccess(BaladesDataContext dataContext)
            : base(dataContext)
        {
            DataLoadOptions loadOptions = new DataLoadOptions();
            loadOptions.LoadWith<Visit>(v => v.Pictures);
            loadOptions.LoadWith<Visit>(v => v.Informations);
            loadOptions.LoadWith<Visit>(v => v.VisitQuality);

            DataContext.LoadOptions = loadOptions;
        }

        public IEnumerable<VisitQuality> GetVisitQualities()
        {
            List<VisitQuality> results = new List<VisitQuality>();
            IEnumerable<Visit> visits = DataContext.Visits;

            foreach (Visit visit in visits)
            {
                VisitQuality visitQuality;

                if (visit.VisitQuality != null)
                    visitQuality = visit.VisitQuality;
                else
                    visitQuality = new VisitQuality();

                visitQuality.VisitID = visit.VisitID;
                visitQuality.Title = visit.Title;
                visitQuality.Visible = visit.Visible;

                if (string.IsNullOrEmpty(visit.SumUp))
                    visitQuality.SumUp = false;
                if (string.IsNullOrEmpty(visit.Text))
                    visitQuality.Text = false;

                if (visit.MarketingCategoryID == null)
                    visitQuality.Categories = false;
                if (visit.PlaceCategoryID == null)
                    visitQuality.Categories = false;

                if (visit.Pictures.Count < 10)
                    visitQuality.Pictures = false;

                if (visit.Informations.Count < 9)
                    visitQuality.Informations = false;

                if (visit.Latitude == null)
                    visitQuality.Gps = false;
                if (visit.Longitude == null)
                    visitQuality.Gps = false;

                results.Add(visitQuality);
            }
            return results;
        }

        public void Update(VisitQuality visitQuality)
        {
            
        }
    }
}
